package com.mentaleye.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mentaleye.bean.PermissionsRoleKeyBean;
import com.mentaleye.dal.dao.PermissionsRoleDao;
import com.mentaleye.dal.model.PermissionsRoleKey;
import com.mentaleye.service.PermissionsRoleService;
import com.mentaleye.util.ObjectUtil;
@Service
public class PermissionsRoleServiceImpl implements PermissionsRoleService{

	@Autowired private PermissionsRoleDao permissionsRoleDao;
	@Override
	public boolean addPermissionsRole(PermissionsRoleKeyBean permissionsRoleBean) {
		PermissionsRoleKey permissionsRole=tansfer(permissionsRoleBean);
		return permissionsRoleDao.insertPermissionsRole(permissionsRole);
		
	}

	@Override
	public boolean deletePermissionsRole(Integer roleNo) {
		return permissionsRoleDao.deletePermissionsRole(roleNo);
	}

	@Override
	public List<PermissionsRoleKeyBean> queryPermissionsRole(Integer roleId) {
		return tansfer(permissionsRoleDao.queryPermissionsRole(roleId));
	}

	
	public PermissionsRoleKeyBean tansfer(PermissionsRoleKey permissionsRole){
		PermissionsRoleKeyBean permissionsRoleBean=new PermissionsRoleKeyBean();
		permissionsRoleBean.setPermissionsId(permissionsRole.getPermissionsId());
		permissionsRoleBean.setRoleNo(permissionsRole.getRoleNo());
		return permissionsRoleBean;
	}
	
	public PermissionsRoleKey tansfer(PermissionsRoleKeyBean permissionsRoleBean){
		PermissionsRoleKey permissionsRole=new PermissionsRoleKey();
		permissionsRole.setPermissionsId(permissionsRoleBean.getPermissionsId());
		permissionsRole.setRoleNo(permissionsRoleBean.getRoleNo());
		return permissionsRole;
	}
	
	public List<PermissionsRoleKeyBean> tansfer(List<PermissionsRoleKey> permissionsRoles){
		List<PermissionsRoleKeyBean> permissionsRoleBeans=new ArrayList<PermissionsRoleKeyBean>();
		if(permissionsRoles==null)
			return null;
		for (PermissionsRoleKey permissionsRole : permissionsRoles) {
			permissionsRoleBeans.add(tansfer(permissionsRole));
		}
		return permissionsRoleBeans;
	}

	@Override
	public boolean updatePermissionsRole(PermissionsRoleKeyBean permissionsRoleBean) {
		PermissionsRoleKey permissionsRole=tansfer(permissionsRoleBean);
		return permissionsRoleDao.updatePermissionsRole(permissionsRole);
	}

	@Override
	public boolean addPermissionsRoleList(List<PermissionsRoleKeyBean> listBean) {
		return permissionsRoleDao.insertPermissionsRoleList(ObjectUtil.transferList(listBean, PermissionsRoleKey.class));
	}

}
